package com.example.mall.web.controller;

import com.example.mall.domain.PaymentRecords;
import com.example.mall.dto.PaymentRecordsDto;
import com.example.mall.exception.ErrorEnumCode;
import com.example.mall.exception.GlobalCustomerException;
import com.example.mall.query.PageDTO;
import com.example.mall.query.PaymentRecordsQuery;
import com.example.mall.result.JSONResult;
import com.example.mall.service.IPaymentRecordsService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/paymentRecords")
public class PaymentRecordsController {

    @Autowired
    public IPaymentRecordsService paymentRecordsService;

    /**
     * 分页查询支付记录表信息
     * @param paymentRecordsQuery
     * @return
     */
    @GetMapping("queryPage")
    @ApiOperation(value = "分页查询支付记录表信息",notes = "分页查询支付记录表信息",httpMethod = "GET")
    public JSONResult queryPage(PaymentRecordsQuery paymentRecordsQuery){
        PageDTO<PaymentRecordsDto> paymentRecordsDtoPageDTO = paymentRecordsService.queryPage(paymentRecordsQuery);
        return JSONResult.success("查询成功",paymentRecordsDtoPageDTO);
    }

    /**
     * 根据id查询支付记录表信息
     * @param paymentId
     * @return
     */
    @GetMapping("query/{paymentId}")
    @ApiOperation(value = "根据id查询支付记录表信息",notes = "根据id查询支付记录表信息",httpMethod = "GET")
    public JSONResult query(@PathVariable("paymentId")Long paymentId){
        //1.根据id查询用户信息
        if (paymentId == null){
            throw new GlobalCustomerException(ErrorEnumCode.PAYMENT_RECORDS_NOT_ID);
        }
        PaymentRecords paymentRecords = paymentRecordsService.getById(paymentId);
        return JSONResult.success("查询成功",paymentRecords);
    }

    /**
     * 根据id查询支付记录表信息
     * @param paymentId
     * @return
     */
    @GetMapping("queryPaymentRecordsById/{paymentId}")
    @ApiOperation(value = "根据id查询支付记录表信息",notes = "根据id查询支付记录表信息",httpMethod = "GET")
    public JSONResult queryPaymentRecordsById(@PathVariable("paymentId")Long paymentId){
        //1.根据id查询用户信息
        if (paymentId == null){
            throw new GlobalCustomerException(ErrorEnumCode.PAYMENT_RECORDS_NOT_ID);
        }
        PaymentRecords paymentRecords = paymentRecordsService.queryPaymentRecordsById(paymentId);
        return JSONResult.success("查询成功",paymentRecords);
    }

    /**
     * 查询全部支付记录表信息
     * @param
     * @return
     */
    @GetMapping("queryPaymentRecordsList")
    @ApiOperation(value = "查询全部支付记录表信息",notes = "查询全部支付记录表信息",httpMethod = "GET")
    public JSONResult queryPaymentRecordsList(){
        List<PaymentRecords> paymentRecords = paymentRecordsService.queryPaymentRecordsList();
        return JSONResult.success("查询成功",paymentRecords);
    }

    /**
     * 新增支付记录表
     * @param paymentRecordsDto
     * @return
     */
    @PostMapping("insert")
    @ApiOperation(value = "新增支付记录表",notes = "新增支付记录表",httpMethod = "POST")
    public JSONResult insert(@RequestBody PaymentRecordsDto paymentRecordsDto){
        paymentRecordsService.insert(paymentRecordsDto);
        return JSONResult.success("保存成功");
    }

    /**
     * 修改支付记录表信息
     * @param paymentRecordsDto
     * @return
     */
    @PostMapping("update")
    @ApiOperation(value = "修改支付记录表信息",notes = "修改支付记录表信息",httpMethod = "POST")
    public JSONResult update(@RequestBody PaymentRecordsDto paymentRecordsDto){
        paymentRecordsService.update(paymentRecordsDto);
        return JSONResult.success("修改成功");
    }

    /**
     * 删除支付记录表信息
     * @param paymentId
     * @return
     */
    @PostMapping("delete/{paymentId}")
    @ApiOperation(value = "删除支付记录表信息",notes = "删除支付记录表信息",httpMethod = "POST")
    public JSONResult delete(@PathVariable("paymentId") Long paymentId) {
        paymentRecordsService.delete(paymentId);
        return JSONResult.success("删除成功");
    }

    /**
     * 批量删除支付记录表信息
     * @param paymentIds
     * @return
     */
    @PostMapping("deleteBatch")
    @ApiOperation(value = "批量删除支付记录表信息",notes = "批量删除支付记录表信息",httpMethod = "POST")
    public JSONResult deleteAll(@RequestBody List<Long> paymentIds) {
        paymentRecordsService.deleteBatch(paymentIds);
        return JSONResult.success("批量删除成功");
    }
}
